﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CSUI.Images
{
    

    public class SelectListItem
    {
        public string Text { get; set; }
        public string Value { get; set; }
    }
   
    public class CommClass
    {

        private static string date;
        public static void DataBind(ComboBox cb,string name)
        {
            if (name == "YY")
                cb.DataSource = GetYearSelectList().ToList();
            if (name == "MM")
                cb.DataSource = GetMonthSelectList().ToList();
            if (name == "DD")
                cb.DataSource = GetDaySelectList().ToList();

            cb.ValueMember = "Value";
            cb.DisplayMember = "Text";
            //cb.SelectedIndexChanged += new EventHandler(Age);
            if (cb.Name == "comboBox3") return;
            //cb.SelectedIndexChanged += new EventHandler(CombS);
        }
        public static IEnumerable<SelectListItem> GetYearSelectList()
        {
            for (var i = 1900; i <= 3000; i++)
            {
                yield return new SelectListItem { Text = i.ToString() + "年", Value = i.ToString() };
            }
        }
        public static IEnumerable<SelectListItem> GetMonthSelectList()
        {
            for (var i = 1; i <= 12; i++)
            {
                yield return new SelectListItem { Text = i.ToString() + "月", Value = i.ToString() };
            }
        }

        public static void Fzyymm(string yy,string mm)
        {
             date= $"{ yy}+{mm}";
        }
        
        public static IEnumerable<SelectListItem> GetDaySelectList()
        {
            string[] fzyymm = date.Split('+');
            var anyDate = new DateTime(Convert.ToInt32(fzyymm[0]), Convert.ToInt32(fzyymm[1]),1);
            var lastDayOfMonth = anyDate.AddMonths(1).AddDays(-1).Day; //该月最后一天
            for (var d = 1; d <= lastDayOfMonth; d++)
            {
                yield return new SelectListItem { Text = d.ToString() + "号", Value = d.ToString() };
            }
        }
    }
}
